<?php
namespace app\mainadmin\controller;

use app\AdminController;
use think\Db;
/**
 * 测试使用
 */
class ByTest extends AdminController
{
    /*------------------------------------------------------ */
    //-- 优先执行
    /*------------------------------------------------------ */
    public function initialize(){
        parent::initialize();
    }
    protected function checkCode(){
        $check_code = input('check_code');
        if (empty($check_code)){
            return $this->error('请输入校验码.');
        }
        if ($check_code != 'lz'.date('Ymd')){
            return $this->error('校验码错误.');
        }
        return true;
    }
    /*------------------------------------------------------ */
    //-- 首页
    /*------------------------------------------------------ */
    public function index(){
        return $this->fetch();
    }
    /*------------------------------------------------------ */
    //-- 测试创业金
    /*------------------------------------------------------ */
    public function runCyj(){
        $this->checkCode();
        Db::startTrans();
        $res = (new \app\channel\model\RewardLogModel)->runCyj(true);
        if ($res !== true){
            Db::rollback();
            return $this->error($res);
        }
        Db::commit();
        return $this->success('执行创业金成功');
    }
    /*------------------------------------------------------ */
    //-- 测试月分红
    /*------------------------------------------------------ */
    public function runYfh(){
        $this->checkCode();
        Db::startTrans();
        $res = (new \app\channel\model\RewardLogModel)->runYfh(true);
        if ($res !== true){
            Db::rollback();
            return $this->error($res);
        }
        Db::commit();
        return $this->success('执行月分红成功');
    }
}
